package com.spring.mybatis.anno.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.spring.mybatis.anno.po.Car;
import com.spring.mybatis.anno.service.CarService;


@RestController
public class CarController {

  @Autowired
  CarService carService;

  @RequestMapping(value = "/cars", method = RequestMethod.GET)
  public List<Car> getAll() {
    return carService.selectAll();
  }

  @RequestMapping(value = "/car/{id}", method = RequestMethod.GET)
  public Car getById(@PathVariable("id") String id) {
    return carService.selectById(id);
  }

  @RequestMapping(value = "/car", method = RequestMethod.POST)
  public Car add(@RequestBody Car car) {
    Long insert = carService.insert(car);
    System.out.println("添加的id=[" + insert + "]的用户");
    return car;
  }

  @RequestMapping(value = "/car/{id}", method = RequestMethod.PUT)
  public Car update(@PathVariable Long id, @RequestBody Car car) {
    car.setId(id);
    carService.update(car);
    return car;
  }

  @RequestMapping(value = "/car/{id}", method = RequestMethod.DELETE)
  public boolean delete(@PathVariable Long id) {
    return carService.delete(id);
  }
}
